//
//  ReimbursementListViewController.swift
//  HuaYun
//
//  Created by enghou on 2018/11/19.
//  Copyright © 2018 xyxorigation. All rights reserved.
//

import UIKit

class ReimbursementListViewController: RefreshedTableViewController {
    
    let approvalBtn = UIButton.init(type: .system)

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        approvalBtn.setTitle("申请差旅报销", for: .normal)
        
        approvalBtn.setTitleColor(UIColor.white, for: .normal)
        
        approvalBtn.setTitleColor(UIColor.hex("999999"), for: .disabled)
        
        approvalBtn.backgroundColor = UIColor.mainColor
        
        approvalBtn.titleLabel?.font = UIFont.systemFont(ofSize: 17)
        
        approvalBtn.addTarget(self, action: #selector(toApproval), for: .touchUpInside)
        
        self.view.addSubview(approvalBtn)
        
        self.tableView.register(UINib.init(nibName: "ProjectListCell", bundle: Bundle.main), forCellReuseIdentifier: "ProjectListCell")
        self.beginRefresh()
        // Do any additional setup after loading the view.
    }
    
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        approvalBtn.top = self.view.bottom - 55
        approvalBtn.height = 55
        approvalBtn.left = 0
        approvalBtn.width = UIScreen.main.bounds.size.width
        self.tableView.top = 0
        self.tableView.left = 0
        self.tableView.width = UIScreen.main.bounds.size.width
        self.tableView.height = self.view.height - 55
    }
    
    @objc func toApproval() -> Void {
        let vc = RequestFinacialReimbursementViewController()
        vc.title = "申请差旅报销"
        self.push(destination: vc)
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        return tableView.dequeueReusableCell(withIdentifier: "ProjectListCell")!
    }
    
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
    
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        let json = self.source[indexPath.row]
        cell.selectionStyle = .none
        let cel = cell as! ProjectListCell
        cel.model = json
    }
    
    override func path(for name: String) -> String {
        return BXList
    }
    
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let json = source[indexPath.row]
        let container = ReimbursementDetailViewController()
        container.id = json.contents?["id"]?.rawString() ?? ""
        container.title = "报销详情"
        container.ifneedapproal = false
        self.push(destination: container)
    }

}
